package com.cdyx.outsideprescription.util;

import com.baomidou.mybatisplus.generator.config.IFileCreate;
import jdk.nashorn.internal.ir.CallNode;

import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;

public class ObjMapUtils {
    /**
     *将对象转换为map
     */
    public static Map<String,Object> obj2Map(Object object) throws IllegalAccessException {
        if (object==null){
            throw new NullPointerException("转换对象不能为空！！！");
        }
        Map<String,Object> map =new LinkedHashMap<>();
        Field[] declaredFields = object.getClass().getDeclaredFields();
        for (Field declaredField:declaredFields
             ) {
            declaredField.setAccessible(true);
            String name = declaredField.getName();
            Object value = declaredField.get(object);
            if (! "serialVersionUID".equals (name)|| !"prescriptionUploadConfig".equals (name)){
                if (value!=null){
                    map.put(name,value);
                }
            }
        }
        return map;
    }

}
